package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ErrorManager;
import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;
import ar.edu.caece.compiler.grammar.attributes.Attribute;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.OP12;
import ar.edu.caece.compiler.grammar.terminals.SumaNaturalToken;

public class OP12Factory extends AbstractTokenVisitorFactory {

	private static OP12Factory INSTANCE;
	
	public static OP12Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new OP12Factory();
		return INSTANCE;
	}
	
	private OP12Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new SumaNaturalToken.SumaNaturalChainVisitor(siguiente) {
			
			@Override
			public Recognizer sumaNaturalCase(SumaNaturalToken llamador) {
				OP12 op12 = new OP12(llamador);
				op12.addAttribute("tipo", new StringAttribute("NATURAL"));
				op12.addAttribute(Attribute.OPERACION, new StringAttribute("SUMA"));

				return op12;
			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new SumaNaturalToken.SumaNaturalTokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				ErrorManager.getInstance().manage(llamador,"OP12",new ParsingException("Error de parsing.",OP12.class,llamador));
				return null;
			}
			
			@Override
			public Recognizer sumaNaturalCase(SumaNaturalToken llamador) {
				OP12 op12 = new OP12(llamador);
				op12.addAttribute("tipo", new StringAttribute("NATURAL"));
				op12.addAttribute(Attribute.OPERACION, new StringAttribute("SUMA"));

				return op12;
			}
		};
	}
	
	
}
